import request from '../utils/request'

// 用户管理相关API
export const userApi = {
  // 获取用户列表
  getUserList: (params?: any) => {
    return request.get('/users', { params })
  },

  // 获取用户详情
  getUserDetail: (id: number) => {
    return request.get(`/users/${id}`)
  },

  // 创建用户
  createUser: (data: any) => {
    return request.post('/users', data)
  },

  // 更新用户信息
  updateUser: (id: number, data: any) => {
    return request.put(`/users/${id}`, data)
  },

  // 启用/禁用用户
  updateUserStatus: (id: number, data: { status: number }) => {
    return request.put(`/users/${id}/status`, data)
  },

  // 修改用户角色
  updateUserRole: (id: number, data: { roleId: number }) => {
    return request.put(`/users/${id}/role`, data)
  }
}

// 角色管理相关API
export const roleApi = {
  // 获取角色列表
  getRoleList: () => {
    return request.get('/roles')
  },

  // 创建角色
  createRole: (data: any) => {
    return request.post('/roles', data)
  },

  // 更新角色
  updateRole: (id: number, data: any) => {
    return request.put(`/roles/${id}`, data)
  },

  // 删除角色
  deleteRole: (id: number) => {
    return request.delete(`/roles/${id}`)
  },

  // 获取角色的权限列表
  getRolePermissions: (id: number) => {
    return request.get(`/roles/${id}/permissions`)
  },

  // 为角色分配权限
  assignPermissions: (id: number, data: { permissionIds: number[] }) => {
    return request.post(`/roles/${id}/permissions`, data)
  }
}

// 权限管理相关API
export const permissionApi = {
  // 获取权限列表
  getPermissionList: () => {
    return request.get('/permissions')
  },

  // 创建权限
  createPermission: (data: any) => {
    return request.post('/permissions', data)
  },

  // 更新权限
  updatePermission: (id: number, data: any) => {
    return request.put(`/permissions/${id}`, data)
  },

  // 删除权限
  deletePermission: (id: number) => {
    return request.delete(`/permissions/${id}`)
  },

  // 移除角色权限
  removePermissionFromRole: (roleId: number, permissionId: number) => {
    return request.delete(`/roles/${roleId}/permissions/${permissionId}`)
  }
}

// 菜单管理相关API
export const menuApi = {
  // 获取菜单列表
  getMenuList: () => {
    return request.get('/menus')
  },

  // 获取菜单详情
  getMenuDetail: (id: number) => {
    return request.get(`/menus/${id}`)
  },

  // 创建菜单
  createMenu: (data: any) => {
    return request.post('/menus', data)
  },

  // 更新菜单
  updateMenu: (id: number, data: any) => {
    return request.put(`/menus/${id}`, data)
  },

  // 删除菜单
  deleteMenu: (id: number) => {
    return request.delete(`/menus/${id}`)
  },

  // 更新菜单状态
  updateMenuStatus: (id: number, data: { status: number }) => {
    return request.put(`/menus/${id}/status`, data)
  }
}

// 操作日志相关API
export const logApi = {
  // 获取操作日志列表
  getLogList: (params?: any) => {
    return request.get('/operation-logs', { params })
  },

  // 获取操作日志详情
  getLogDetail: (id: number) => {
    return request.get(`/operation-logs/${id}`)
  },

  // 删除操作日志
  deleteLog: (id: number) => {
    return request.delete(`/operation-logs/${id}`)
  },

  // 批量删除操作日志
  batchDeleteLogs: (ids: number[]) => {
    return request.post('/operation-logs/batch-delete', ids)
  }
}

// 文件管理相关API
export const fileApi = {
  // 获取文件列表
  getFileList: (params?: any) => {
    return request.get('/files', { params })
  },

  // 上传文件
  uploadFile: (data: FormData) => {
    return request.post('/files', data)
  },

  // 下载文件
  downloadFile: (id: number) => {
    return request.get(`/files/${id}/download`)
  },

  // 删除文件
  deleteFile: (id: number) => {
    return request.delete(`/files/${id}`)
  }
}

// 评价管理相关API
export const reviewApi = {
  // 获取评价列表
  getReviewList: (params?: any) => {
    return request.get('/reviews', { params })
  },

  // 更新评价状态
  updateReviewStatus: (id: number, data: { status: number }) => {
    return request.put(`/reviews/${id}/status`, data)
  },

  // 删除评价
  deleteReview: (id: number) => {
    return request.delete(`/reviews/${id}`)
  }
}